
package com.example.tang.zhayan.ui;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;

import com.example.tang.zhayan.R;
import com.example.tang.zhayan.utils.AnimationUtils;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

/**
 * Created by tang on 2015/12/12.
 * 欢迎界面
 */
@ContentView(R.layout.activity_guide)
public class GuideActivity extends AppCompatActivity {
    @ViewInject(R.id.image_guide)
    private ImageView imgGuider;
    private SharedPreferences preferences;
    private String isFirst = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
        preferences = getSharedPreferences("msg", Context.MODE_PRIVATE);
        isFirst = preferences.getString("isFirst", "");
        if (isFirst.equals("")) {
            SharedPreferences.Editor editor = preferences.edit();
            editor.putString("isFirst", "yes");
            editor.commit();
        }


        //跳转动画
        TranslateAnimation animation = AnimationUtils.getTransalateAnimation();
        imgGuider.startAnimation(animation);
        animation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                //如果是第一次进来就跳转到主导界面
                if (isFirst.equals("")) {
                    Intent intent = new Intent(GuideActivity.this, SplashActivity.class);
                    startActivity(intent);
                } else {
                    //否则直接跳转到主界面
                    Intent intent = new Intent(GuideActivity.this, MainActivity.class);
                    startActivity(intent);
                }

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }

    /**
     * 返回的时候直接退出
     */
    @Override
    protected void onRestart() {
        super.onRestart();
        this.finish();
    }
}
